package view;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

import java.awt.*;

import javax.swing.*;

import org.jdesktop.xswingx.PromptSupport;

import types.ConsoleType;
import controller.Console;
import controller.Login;

@SuppressWarnings("serial")
public class loginPanel extends JPanel {

	private static loginPanel single;

	private JLabel title = new JLabel("Docenten Absentie Systeem");
	// private JLabel password = new JLabel("Wachtwoord: ");
	// private JLabel username = new JLabel("Gebruikersnaam: ");

	private JPasswordField passwordField = new JPasswordField();
	private JTextField usernameField = new JTextField();
	BufferedImage myPicture = null;

	private JButton loginButon = new JButton("Inloggen");
	private JButton JBafsluiten = new JButton("Afsluiten");
	private JButton overDAS = new JButton("Over DAS");

	private loginPanel() {

		setLayout(null);
		setSize(1200, 800);

		// set bounds
		title.setBounds(170, 90, 600, 70);
		title.setFont(new Font("Serif", Font.BOLD, 50));

		//username.setBounds(270, 265, 100, 25);
		usernameField.setBounds(405, 265, 200, 25);

		//password.setBounds(270, 295, 100, 25);
		passwordField.setBounds(405, 295, 200, 25);

		loginButon.setBounds(405, 325, 200, 35);

		overDAS.setBounds(437, 400, 125, 25);
		JBafsluiten.setBounds(437, 435, 125, 25);

		PromptSupport.setPrompt("Gebruikersnaam", usernameField);
		PromptSupport.setPrompt("Wachtwoord", passwordField);

		// actionlisteners

		loginButon.addActionListener(new Login(this));

		passwordField.addKeyListener(new Login(this));
		usernameField.addKeyListener(new Login(this));

		JBafsluiten.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				Main_Frame mf = Main_Frame.getInstance();
				mf.dispose();
			}
		});

		overDAS.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				Main_Frame mf = Main_Frame.getInstance();
				mf.remove(loginPanel.getInstance());
				mf.add(PanelOverDAS.getInstance());
				mf.repaint();
				mf.validate();
			}
		});

		// add all to panel
		add(title);
		add(loginButon);
		add(JBafsluiten);
	//	add(username);
		add(usernameField);
	//	add(password);
		add(passwordField);
		add(overDAS);

	}

	// getters and setters
	public static loginPanel getInstance() {
		if (single == null) {
			single = new loginPanel();
		}
		return single;
	}

	public static loginPanel getSingle() {
		return single;
	}

	public static void setSingle(loginPanel single) {
		loginPanel.single = single;
	}

	public JLabel getTitle() {
		return title;
	}

	public void setTitle(JLabel title) {
		this.title = title;
	}

	//public JLabel getPassword() {
	//	return password;
	//}

	//public void setPassword(JLabel password) {
	//	this.password = password;
	//}

	public JTextField getPasswordField() {
		return passwordField;
	}

	public void setPasswordField(JPasswordField passwordField) {
		this.passwordField = passwordField;
	}

	public JButton getLoginButon() {
		return loginButon;
	}

	public void setLoginButon(JButton loginButon) {
		this.loginButon = loginButon;
	}

	public JButton getJBafsluiten() {
		return JBafsluiten;
	}

	public void setJBafsluiten(JButton jBafsluiten) {
		JBafsluiten = jBafsluiten;
	}

	//public JLabel getUsername() {
	//	return username;
	//}

	//public void setUsername(JLabel username) {
	//	this.username = username;
	//}

	public JTextField getUsernameField() {
		return usernameField;
	}

	public void setUsernameField(JTextField usernameField) {
		this.usernameField = usernameField;
	}

}
